package com.digitalart.futbol.hibernate.daoImpl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.digitalart.futbol.hibernate.dao.ReservacionDao;
import com.digitalart.futbol.hibernate.ejb.Cancha;
import com.digitalart.futbol.hibernate.ejb.Reservacion;
@Repository
public class ReservacionDaoImpl implements ReservacionDao {

	@Autowired
	private SessionFactory sessionFactory;

	@Transactional
	public Reservacion findById(int id) {
		String queryString= "from Reservacion reservacion where reservacion.id_reservacion=?";

		Reservacion result = (Reservacion) this.sessionFactory.getCurrentSession().createQuery(queryString).setParameter(0, id).uniqueResult();	

		return result;
	}

	@Transactional
	public Reservacion persistOnMerge(Reservacion objReservacion) {
		Reservacion result = (Reservacion)this.sessionFactory.getCurrentSession().merge(objReservacion);

		return result;
	}

	@Override
	public List<Reservacion> getAll() {
		String queryString= "from Reservacion reservacion";

		List<Reservacion> result = (List) this.sessionFactory.getCurrentSession().createQuery(queryString).list();	

		return result;
	}

}
